import requests
import time
import random
from ddddocr import DdddOcr



while True:
# 1. 获取图片以及captchaKey
    img_res = requests.get(f'https://www.labnetwork.com.cn/gateway/basic/mall/oauth/code?{random.random()}')
    img_data = img_res.json()['data']

    ocr = DdddOcr(show_ad=False)
    r = ocr.classification(img_data['img'][22:])
    print(f"图片 {img_data['uuid']}  识别结果 {r}")



    # 2. 将验证码以及用户信息 发起登录请求
    time.sleep(1)
    login_res = requests.post('https://www.labnetwork.com.cn/gateway/basic/mall/oauth/login', json={
        "userEmail": "1405245978@qq.com",
        "password": "Wondayays520",
        "captchaCode": f"{r}",
        "captchaKey": f"{img_data['uuid']}"
    })

    if "验证码错误" in login_res.text:
        print(f"验证码识别错误")
    else:
        token = login_res.json()['data']['userInfo']['token']

        break

print(token)